package edu.buaa.common.transaction;

import edu.buaa.common.utils.PVal;
import edu.buaa.utils.Helper;
import edu.buaa.utils.Pair;

import java.util.List;
import java.util.stream.Collectors;

public class SnapshotQueryTx extends AbstractTransaction {

    private boolean isNode = false;

    private int timestamp;

    private String propertyName;

    public SnapshotQueryTx() {
        this.setTxType(TxType.tx_query_snapshot);
    }

    public int getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }

    public String getPropertyName() {
        return propertyName;
    }

    public void setPropertyName(String propertyName) {
        this.propertyName = propertyName;
    }

    public boolean isNode() {
        return isNode;
    }

    public void setNode(boolean node) {
        isNode = node;
    }

    public static class Result extends AbstractTransaction.Result {
        List<Pair<String, PVal>> status;

        public List<Pair<String, PVal>> getStatus() {
            return status;
        }

        public void setStatus(List<Pair<String, PVal>> status) {
            this.status = status;
        }
    }

    @Override
    public boolean validateResult(AbstractTransaction.Result result) {
        return Helper.validateResult(conv(((Result) this.getResult()).getStatus()), conv(((Result) result).getStatus()));
    }

    private List<Pair<String, PVal>> conv(List<Pair<String, PVal>> from){
        return from.stream().map(t2 -> Pair.of(t2.getKey(), t2.getValue())).collect(Collectors.toList());
    }
}
